<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="item in list">
          {{ item.name }}的库存还剩
          <input type="number" v-model.number="item.count" />件 -
          <span v-if="item.count === 0">卖完了</span>
        </li>
      </ul>
      <p>总库存为: {{sum}}</p>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            list: [
              {
                name: "苹果",
                count: 4,
              },
              {
                name: "西瓜",
                count: 0,
              },
              {
                name: "香蕉",
                count: 3,
              },
            ],
          };
        },
        computed: {
          sum() {
            return this.list.reduce((s, item) => {
              return (s += item.count);
            }, 0);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
